package com.demo.demo.rabbitmq.work;

import com.demo.demo.utils.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Provider {
    /**
     * 直接发送到消息队列
     * 每个消费者消费的消息是平均分配的
     * @param args
     * @throws IOException
     * @throws TimeoutException
     */
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("work",true,false,false,null);

        for (int i = 1;i<=100;i++) {
            channel.basicPublish("", "work", null, (i+"work models").getBytes());
        }

        RabbitMQUtils.closeConnectionAndChanel(channel,connection);
    }
}
